﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2011/10/27 21:45:03
 *      Version:        1.0.1101
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Sector7.Framework.Utility
{
    /// <summary>
    /// 目录工具类
    /// </summary>
    public class PathUtil
    {
        #region Public functions
        /// <summary>
        /// 检查牧师是否存在，若不存在则自动创建
        /// </summary>
        /// <param name="path">目录路径</param>
        public static void CheckExists(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }

        /// <summary>
        /// 生成目录路径
        /// </summary>
        /// <param name="basePath">基础路径</param>
        /// <param name="subPath">子目录名</param>
        /// <returns></returns>
        public static string Combine(string basePath, string subPath)
        {
            basePath = basePath.Replace("/", "\\");
            subPath = subPath.Replace("/", "\\");

            return Path.Combine(basePath, subPath); ;
        }

        /// <summary>
        /// 生成目录路径
        /// </summary>
        /// <param name="subPath">子目录名</param>
        /// <returns></returns>
        public static string Combine(string subPath)
        {
            return Combine(ApplicationUtil.GetBaseDirectory(), subPath);
        }

        /// <summary>
        /// 组合指定目录或文件名的路径
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        public static string CombinePath(params string[] paths)
        {
            string targetPath = string.Empty;
            foreach (var path in paths)
            {
                targetPath = Path.Combine(targetPath, path);
            }

            return targetPath;
        }

        /// <summary>
        /// 生成包含应用程序启动路径的绝对路径
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        public static string GenerateAbsPath(params string[] paths)
        {
            string basePath = ApplicationUtil.GetBaseDirectory();

            string targetPath = basePath;
            foreach (var path in paths)
            {
                targetPath = Path.Combine(targetPath, path);
            }

            return targetPath;
        }
        #endregion
    }
}
